/*
 * TMap Designer - A Thematic Map design software
 * Copyright (C) 2006 World Health Organization
 * http://www.who.int
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
package who.tmap.ui;

import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 * A warning dialog when geographic box has not been initialized
 * @author stl
 *
 */
public class JDialogGeoBoxNotInitializedWarning extends JDialog {
	
	private JPanel jContentPane = null;
	private JPanel jPanelInfo = null;
	private JLabel jLabel1 = null;
	private JPanel jPanelButtons = null;
	private JButton jButtonIgnore = null;
	private JButton jButtonEditGeoBox = null;	
	private JLabel jLabel2 = null;
	boolean editGeoBox =false;
	
	/**
	 * This is the default constructor
	 */
	public JDialogGeoBoxNotInitializedWarning( Frame parent, boolean modal ) {
		super( parent, modal );

		initialize();
	}
	
	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setTitle("Warning");
		this.setBounds(new Rectangle(0,0,400,150));
		this.setContentPane(getJContentPane());
		this.setLocationRelativeTo( null );
		
		getRootPane().setDefaultButton( getJButtonIgnore() );
	}

	private JPanel getJContentPane() {
		if(jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(new BorderLayout());
			jContentPane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
			jContentPane.add(getJPanelInfo(), BorderLayout.NORTH);
			jContentPane.add(getJPanelButtons(), BorderLayout.SOUTH);
		}
		return jContentPane;
	}
   
	private JPanel getJPanelInfo() {
		if (jPanelInfo == null) {
			jPanelInfo = new JPanel();
			jLabel1 = new JLabel();
			jLabel1.setText("The geographic coordinates have not been initialized:");			
			jLabel2 = new JLabel();
			jLabel2.setText("It is recommended to edit the geographic box now !");
			GridLayout gridLayout = new GridLayout(3,2,5,5);

			jPanelInfo.setLayout(gridLayout);
			jPanelInfo.add(jLabel1, null);
			jPanelInfo.add(jLabel2, null);
		}
		return jPanelInfo;
	}

	private JPanel getJPanelButtons() {
		if (jPanelButtons == null) {
			jPanelButtons = new JPanel();

			jPanelButtons.add(getJButtonEditGeoBox(), null);	
			jPanelButtons.add(getJButtonIgnore(), null);

		}
		return jPanelButtons;
	}
  
	private JButton getJButtonIgnore() {
		if (jButtonIgnore == null) {
			jButtonIgnore = new JButton();
			jButtonIgnore.setText("Ignore");

			jButtonIgnore.addActionListener(new ActionListener() { 
				public void actionPerformed(ActionEvent e) {
					setVisible( false );
				}
			});
		}
		return jButtonIgnore;
	}
  
	private JButton getJButtonEditGeoBox() {
		if (jButtonEditGeoBox == null) {
			jButtonEditGeoBox = new JButton();
			jButtonEditGeoBox.setText("Edit Geographic Box...");
			jButtonEditGeoBox.addActionListener(new ActionListener() { 
				public void actionPerformed(ActionEvent e) {
					editGeoBox =true;
					setVisible( false );
				}
			});
		}
		return jButtonEditGeoBox;
	}
	
 }  
